#include "ImageView.h"

ImageView::ImageView(void):_imageData(NULL)
{
#if defined _WIN32
	::InitializeSRWLock(&_lock);
#endif
	
}

void ImageView::initialise(int width,int height){

}
/*
static QImage* IplImage2QImage(IplImage* image){
	QImage qImg =QImage((const unsigned char*)image->imageData,image->width,image->height,QImage::Format_RGB888);
	return &qImg;
} */

void ImageView::enterWriteLock(){
#if defined _WIN32
	AcquireSRWLockExclusive(&_lock);
#endif
}

void ImageView::leaveWriteLock(){
#if defined _WIN32
	ReleaseSRWLockExclusive(&_lock);
#endif
}

void ImageView::enterReadLock(){
#if defined _WIN32
	AcquireSRWLockShared(&_lock);
#endif
}

void ImageView::leaveReadLock(){
#if defined _WIN32
	ReleaseSRWLockShared(&_lock);
#endif
}

void ImageView::updateImage(IplImage* image){
	if(!image) return;
	enterWriteLock();
	if(_imageData){
		cvReleaseImage(&_imageData);
		_imageData = NULL;
	}
	_imageData = cvCloneImage(image);
	leaveWriteLock();
}

ImageView::~ImageView(void){
	if(_imageData) {
		cvReleaseImage(&_imageData);
		_imageData = NULL;
	}
#if defined _WIN32
	
#endif
}